<template>
	<div class="vip">
		<el-row>
			<el-col :span="6">
				<el-button @click="vip" style="width: 100px;margin-left: -240px;">会员列表</el-button>
			</el-col>
			<el-col :span="6">
				<el-button @click="stored" style="width: 100px;margin-left: -740px;">储值管理</el-button>
			</el-col>
			<el-col :span="6">
				<el-button @click="inter" style="width: 100px;margin-left: -1237px;">积分管理</el-button>
			</el-col>
		</el-row>

		<!-- ******************************模糊查询***************************** -->
		<el-form ref="form" :model="form" :inline="true">
			<!-- <el-form-item label="会员等级">
				<el-input v-model="form.vname" placeholder="请输入会员等级"></el-input>
			</el-form-item> -->
			<el-form-item label="会员等级">
				<el-select v-model="form.vipgradeId" placeholder="请选择会员等级" clearable>
					<el-option v-for="g in indentstable" :label="g.name" :value="g.id"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="创建时间">
				<el-date-picker v-model="form.createtime" type="daterange" align="right" unlink-panels range-separator="至"
				 start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" format="yyyy-MM-dd">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="">
				<el-input v-model="form.sname" placeholder="会员卡号/会员姓名/手机号" clearable></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="cx">搜索</el-button>
			</el-form-item>

			<el-form-item label="">
				<el-checkbox>会员到期预警</el-checkbox>
			</el-form-item>

			<el-button type="success" style="float: right;" @click="exportData" icon="el-icon-download">导出</el-button>
		</el-form>


		<!-- **************************列表数据-************************* -->
		<el-table :data="tableData" style="width: 100%" :header-cell-style="{background:'#c2c5f6',color:'black'}">
			<el-table-column type="selection" width="55"></el-table-column>
			<el-table-column prop="id" label="序号">
			</el-table-column>
			<el-table-column prop="cardid" label="卡号">
			</el-table-column>
			<el-table-column label="会员等级" width="100">
				<template v-slot="scope">
					<b style="font-size: 16px;color: gold;">{{scope.row.vname}}</b>
				</template>
			</el-table-column>
			<el-table-column prop="sname" label="会员名称">
			</el-table-column>
			<el-table-column prop="phone" label="手机号">
			</el-table-column>
			<el-table-column prop="consumption" label="累计消费">
			</el-table-column>
			<el-table-column prop="balance" label="存储余额">
			</el-table-column>
			<el-table-column prop="summoney" label="累计余额">
			</el-table-column>
			<el-table-column prop="sumscore" label="积分">
			</el-table-column>
			<el-table-column prop="createtime" label="开卡时间">
			</el-table-column>
			<el-table-column prop="endtime" label="过期时间">
			</el-table-column>
			<el-table-column prop="status" label="状态">
				<!-- <el-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949">
				</el-switch> -->
				<template slot-scope="scope">
					<el-switch v-model="scope.row.isRecommendTwo" active-color="#00ff24" @change="handelUpdate(scope.$index, scope.row)"
					 inactive-color="#DCDFE6" :active-value="true" :inactive-value="false"></el-switch>
				</template>
			</el-table-column>
			<!-- <el-table-column label="操作">
					<template v-slot="scope">
						<el-button type="infor" @click="add(scope.row)">修改</el-button>
						<el-button type="infor" @click="dels(scope.row.id)">删除</el-button>
					</template>
		
				</el-table-column> -->
		</el-table>
		<!-- ********************************分页查询******************************* -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="current"
		 :page-sizes="sizes" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total">
		</el-pagination>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				tableData: [],
				indentstable: [],
				list: [],
				total: 0,
				size: 5,
				sizes: [5, 10, 15],
				current: 1,
				dialogVisible: false,
				formData: {},
				form: {},
				value1: '',
				createtime: [],
				value: true,
				pickerOptions: {
					shortcuts: [{
						text: '最近一周',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
							picker.$emit('pick', [start, end]);
						}
					}, {
						text: '最近一个月',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
							picker.$emit('pick', [start, end]);
						}
					}, {
						text: '最近三个月',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
							picker.$emit('pick', [start, end]);
						}
					}]
				}

			}
		},
		created() {
			this.initDate();
			this.initIndents();
		},
		methods: {
			exportData() {
				var url =
					"http://localhost:8089/vipperson/download";
				window.open(url, "_parent");
			},
			handelUpdate(index, row) {
				// ：active-value得为true
				// ：inactive-value得为false
				let flag = row.isRecommendTwo //保存点击之后v-modeld的值(true，false)

				row.isRecommendTwo = !row.isRecommendTwo //保持switch点击前的状态

				this.$confirm('是否确认此操作?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					if (flag) {
						row.isRecommendTwo = true
						// 逻辑处理
						this.$message.success('打开成功!')
					} else {
						row.isRecommendTwo = false
						// 逻辑处理
						this.$message.success('关闭成功！')
					}
				}).catch(() => {
					this.$message.info('取消操作！')
				});
			},
			vip() {
				this.$router.push("/vip");

			},
			stored() {
				this.$router.push("/stored");
			},
			inter() {
				this.$router.push("/inter");
			},
			initIndents() {
				this.axios.get('http://localhost:8089/vipgrade/list').then((res) => {
					this.indentstable = res.data;
				})
			},
			initDate() {
				this.axios.get('http://localhost:8089/vipperson/list', {
					params: {
						size: this.size,
						current: this.current,
						vname: this.form.vname,
						stime: this.form.createtime ? this.form.createtime[0] : '',
						etime: this.form.createtime ? this.form.createtime[1] : '',
						sname: this.form.sname,
						vipgradeId: this.form.vipgradeId

					}
				}).then(res => {
					if (res) {
						this.tableData = res.data.obj.records
						this.total = res.data.obj.total
					}
				})
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.size = val
				this.initDate()
			},
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.current = val
				this.initDate()
			},
			cx() {
				this.current = 1
				this.initDate()
			}

		}
	}
</script>

<style>
</style>
